<?php


namespace app\admin\model;


use think\Model;

class AdminNode extends Model {

    protected $pk='node_id';

    //获取所有节点菜单
    public function getAll(){
        $where[] = ['is_del','=',0];
        return $this->where($where)->field('node_id as id,node_name as name,parent_id as pId')->select();
    }


    // 写入一条数据
    public function insertOne($data){
        $data['create_time'] = $time = time();
        $data['update_time'] = $time;
        $data['is_del'] = 0;
        return $this->insertGetId($data);
    }

    // 获取一条数据 根据主键
    public function getOne($node_id){

        return $this->where($this->pk,'=',$node_id)->findOrFail();
    }

    // 软删除一条数据
    public function delOne($node_id){
        $data['update_time'] = time();
        $data['is_del'] = 1;
        return $this->where($this->pk,'=',$node_id)->update($data);
    }

    // 更新一条数据
    public function updateOne($node_id,$data){
        $data['update_time'] = time();
        return $this->where($this->pk,'=',$node_id)->update($data);
    }



}